<template>
  <d2-container>
    <el-card shadow="never" class="d2-mb">
      <el-form
        class="filter-container"
        ref="egForm"
        :model="egForm"
        label-width="85px"
      >
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="策略名称">
              <el-input
                placeholder="请输入内容"
                v-model="egForm.strategy_name"
                disabled
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="策略ID">
              <el-input
                disabled
                placeholder="请输入内容"
                v-model="egForm.strategy_id"
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="品名">
              <el-input
                placeholder="请输入内容"
                v-model="egForm.name"
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="部门名称">
              <el-input
                placeholder="请输入内容"
                v-model="egForm.department_name"
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="策略类型">
              <el-select
              :disabled="tp"
                v-model="egForm.strategy_type"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in strategy_type_data"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="策略目的">
              <el-select
                v-model="egForm.strategy_objective"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in strategy_objective_datas"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="2" style="margin:0 0 1% 85%;">
          <el-button type="primary" size="mini" @click="selectData">
            <d2-icon name="search" /> 查询
          </el-button>
        </el-col>
      </el-form>
    </el-card>
    <el-card shadow="never" class="d2-mb">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        highlight-current-row
        @current-change="handleCurrentChange"
      >
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="status" label="状态" sortable></el-table-column>
        <el-table-column prop="org_name" label="机构名称"></el-table-column>
        <el-table-column prop="depart_name" label="部门名称"></el-table-column>
        <el-table-column
          prop="strategy_name"
          label="策略名称"
        ></el-table-column>
        <el-table-column prop="strategy_id" label="策略ID"></el-table-column>
        <el-table-column
          prop="strategy_type"
          label="策略类型"
        ></el-table-column>
        <el-table-column
          prop="strategy_objective"
          label="策略目的"
        ></el-table-column>
        <el-table-column
          prop="max_occupation_funds"
          label="最大占用资金"
        ></el-table-column>
        <el-table-column prop="loss_limit" label="损失限额"></el-table-column>
        <el-table-column
          prop="profit_expectation"
          label="预期盈利"
        ></el-table-column>
        <el-table-column
          prop="risk_profit_ratio"
          label="风险利润比"
        ></el-table-column>
        <el-table-column
          prop="expected_return_on_investment"
          label="预期投资回报"
        ></el-table-column>
        <el-table-column
          prop="strategy_hierarchy"
          label="策略层级"
        ></el-table-column>
        <el-table-column prop="strategy_formulate_date" label="策略制定日期">
          <template slot-scope="scope">{{
            scope.row.strategy_formulate_date | dateYMDHMSFormat
          }}</template>
        </el-table-column>
        <el-table-column
          prop="strategy_start_date"
          label="策略开始日期"
        ></el-table-column>
        <el-table-column
          prop="strategy_end_date"
          label="策略结束日期"
        ></el-table-column>
        <el-table-column prop="creator_name" label="申请人"></el-table-column>
      </el-table>
      <el-pagination
        @current-change="handlePaginationChange"
        :current-page="egForm.page"
        :page-size="egForm.pageSize"
        layout="total, prev, pager, next"
        :total="egForm.pageTotal"
      >
      </el-pagination>
    </el-card>
    <div align="right">
      <el-button size="mini" type="primary" style="margin-right:50px" @click="select_fn"
        >选择</el-button
      >
    </div>
    <!-- <demo-page-footer
      slot="footer"
      :current="page.page"
      :size="page.pageSize"
      :total="page.pageTotal"
      @change="handlePaginationChange"
    /> -->
  </d2-container>
</template>

<script>
import DemoPageFooter from "../../../../../../../components/PageFooter";
import spotFuturesHedging_M from "../model/spotFuturesHedging_M.vue";
import { getStrategy_info } from "@/api/url";
export default {
  components: {
    "demo-page-footer": DemoPageFooter,
    "spot-futures-hedging": spotFuturesHedging_M
  },
  data() {
    return {
      tp:false,
      radioType: 1,
      route_tpyess:this.$route.query.type,
      egForm: {
        strategy_name: "",
        strategy_id: "",
        strategy_type: "",
        strategy_objective: "",
        department_name: "",
        strategy_hierarchy: 2,
        status: 4,
        name: "",
        page: 1,
        pageSize: 20,
        pageTotal: 0
      },
      strategy_objective_datas: [
        {
          value: "1",
          label: "盘面快期套利"
        },
        {
          value: "2",
          label: "期现套利"
        },
        {
          value: "3",
          label: "套期保值"
        },
        {
          value: "4",
          label: "其他"
        }
      ],
      strategy_type_data: [
        {
          value: "1",
          label: "现货期货套期"
        },
        {
          value: "2",
          label: "现货现货套期"
        },
        {
          value: "3",
          label: "现货期权套期",
           disabled: true
        },
        {
          value: "4",
          label: "期货期货套利"
        },
        {
          value: "5",
          label: "现货单边"
        },
        {
          value: "6",
          label: "期货单边"
        }
      ],
      // page: {
      //   page: 1,
      //   pageSize: 5,
      //   pageTotal: 0
      // },
      tableData: [],
      currentRow: null
    };
  },
  created() {
    if(this.route_tpyess==1){
      this.egForm.strategy_type='3'
      this.tp=true
    }
    this.selectData_fn();
  },
  methods: {
    // 清空当前页缓存并刷新此页面
    async handleCleanCacheAndRefreshCurrent() {
      this.keepAliveRemove(this.$route.name);
      await this.$nextTick();
      this.$router.replace("/refresh");
    },
    handlePaginationChange(val) {
      this.egForm.page = val;
      this.selectData_fn();
    },
    selectData_fn() {
      getStrategy_info(this.egForm).then(res => {
        this.tableData = res.result.results;
        this.egForm.pageTotal = res.result.count;
      });
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    selectData() {
      this.egForm.page = 1;
      this.selectData_fn();
    },
    select_fn() {
      if (this.currentRow == null) {
        this.$message({
          message: "请先选择策略",
          type: "warning"
        });
      } else {
        if(this.route_tpyess==1){
          this.$store.commit("SET_SELECTIONSTRATEGY_VUE", this.currentRow);
        this.$router.push("/add_qiquan_orders?type="+1);
        this.closeing.closePage(this.$store.getters["d2admin/page/allPage"],this.$store.getters["d2admin/page/currentPage"])
        }else{
          this.$store.commit("SET_SELECTIONSTRATEGY_VUE", this.currentRow);
        this.$router.push("/add_futures_orders");
        this.closeing.closePage(this.$store.getters["d2admin/page/allPage"],this.$store.getters["d2admin/page/currentPage"])
        }
        
      }
    }
  }
};
</script>
